package com.mlnx.service.common.utils;

/**
 * Created by amanda.shan on 2018/4/28.
 */
public class TimeRecordUtils {

    private static long totalSecondPre10Second = 0;
    private static long flagTime = 0;

    public synchronized Long addTime(long processTime) {
        Long time = null;

        if (flagTime == 0) {
            flagTime = System.currentTimeMillis();
            totalSecondPre10Second = 0;
        }

        totalSecondPre10Second += processTime;

        if (System.currentTimeMillis() - flagTime >= 10 * 1000) {
            time = totalSecondPre10Second / ((System.currentTimeMillis() - flagTime) / 1000);
            flagTime = System.currentTimeMillis();
            totalSecondPre10Second = 0;
        }

        return time;
    }

}
